<?php defined('IN_NWIDC') or exit('Access Invalid!');?>
<link rel="stylesheet" type="text/css" href="<?php echo RESOURCE_SITE_URL;?>/js/jquery-ui/themes/ui-lightness/jquery.ui.css"  />

<style>
  #ui-datepicker-div{
    z-index : 10000 !important;
  }
</style>
<div class="wrap">
  <div class="tabmenu">
    <ul class="tab pngFix">
      <li class="active">
        <a href="javascript:;">代理商申请列表</a></li>
      </ul>
  </div>
  <form method="get" action="index.php" target="_self">
    <table class="ncm-search-table">
      <input type="hidden" name="act" value="member_proxy" />
      <input type="hidden" name='op' value='apply'>
      <!-- <input type="hidden" name= "recycle" value="<?php echo $_GET['recycle'];?>" /> -->
      <tr>
        <td>&nbsp;</td>
        <th>申请状态</th>
        <td class="w100"><select name="state_type">
            <option value="" <?php echo $_GET['state_type']==''?'selected':''; ?>>所有申请</option>
            <option value="state_new" <?php echo $_GET['state_type']=='state_new'?'selected':''; ?>>新申请</option>
            <option value="state_success" <?php echo $_GET['state_type']=='state_success'?'selected':''; ?>>已同意</option>
            <option value="state_cancel" <?php echo $_GET['state_type']=='state_cancel'?'selected':''; ?>>已拒绝</option>
          </select></td>
        <th>申请时间</th>
        <td class="w240"><input type="text" class="text w70" name="query_start_date" id="query_start_date" value="<?php echo $_GET['query_start_date']; ?>"/><label class="add-on"><i class="icon-calendar"></i></label>&nbsp;&#8211;&nbsp;<input type="text" class="text w70" name="query_end_date" id="query_end_date" value="<?php echo $_GET['query_end_date']; ?>"/><label class="add-on"><i class="icon-calendar"></i></label></td>
        <th>申请人ID</th>
        <td class="w160"><input type="text" class="text w150" name="order_sn" value="<?php echo $_GET['order_sn']; ?>"></td>
        <td class="w70 tc"><label class="submit-border">
            <input type="submit" class="submit" value="<?php echo $lang['nc_search'];?>"/>
          </label></td>
      </tr>
    </table>
  </form>
  <style>
    .order tbody tr td{
      padding: 20px 0;
      vertical-align: middle;
      word-break:break-all;
    }
  </style>
  <table class="ncm-default-table order" width='100%'>
    <thead>
      <tr>
        <th width='1%'></th>
        <th width='20%'>用户ID</th>
        <th width='20%'>联系方式</th>
        <th width='30%'>留言</th>
        <th width='10%'>申请状态</th>
        <th>操作</th>
      </tr>
    </thead>
    <?php
      if(count($output['order_pay_list'])){
        foreach($output['order_pay_list'] as $li){
    ?>
    <th colspan="19"> 
      <span class="ml10">
        申请编号：<?php echo 'DLS_' . $li['id'];?>
      </span>
      <span>申请时间：<?php echo date("Y-m-d H:i:s",$li['time'])?></span>
    </th>
    <tr>
      <td>&nbsp;</td>
      <td class='w100' valign='middle'> 
        <?php
          $m = Model('member');
          $user = $m->find($li['member_id']);
          if(empty($user['avatar'])){
            $face = '/data/upload/shop/common/default_user_portrait.gif';
          }
          else{
            $face = '/data/upload/shop/avatar/' . $user_info['avatar'];
          }
        ?>
        <img src="<?php echo $face?>" width='60' height='60' alt="" style='margin-right:10px'>
        <?php
          echo $user['member_name'];
        ?>
      </td>

      <td class='w100' valign='middle'> 
        <?php echo $li['contact']?>
      </td>

      <td class='w200'> 
        <?php 
          if(strlen($li['msg']) > 120){
            $li['msg'] = substr($li['msg'],0,120) . '...';
          }
          echo $li['msg']

        ?>
      </td>

      <td>
        
        <?php 
          switch($li['status']){
            case 'state_new':
              echo '<span style="color:#F30">新申请</span>';
              break;

            case 'state_success':
              echo '<span style="color:#0279B9">已同意</span>';
              break;

            case 'state_cancel':
              echo '<span style="color:#999">已拒绝</span>';
              break;
          }
        ?>
      </td>
      <td>
        <a href="javascript:;" class='showinfo' data-id='<?php echo $li[id]?>'>查看详情</a>
        <?php
          if($li['status'] == 'state_new'){
        ?>
        <a href="javascript:;" class='accept' data-id='<?php echo $li[id]?>'>同意</a>
        <a href="javascript:;" class='reject' data-id='<?php echo $li[id]?>'>拒绝</a>
        <?php
          }
          elseif($li['status'] == 'state_success'){
        ?>
        <a href="javascript:;" class='delete' data-id='<?php echo $li['id']?>'>取消代理</a>
        <?php
          }
        ?>
      </td>

    </tr>
    <?php   
        } 

    ?>

    <?php } else { ?>
    <tbody>
      <tr>
        <td colspan="20" class="norecord"><div class="warning-option"><i>&nbsp;</i><span><?php echo $lang['no_record'];?></span></div></td>
      </tr>
    </tbody>
    <?php } ?>

    <script>
      $('.showinfo').click(function() {
        var id = $(this).attr('data-id');
        layer.open({
          type: 2,
          title: false,
          area : ['800px','650px'],
          skin: 'layui-layer-rim',
          scrollbar  : false,
          content: '/shop/index.php?act=member_proxy&op=get_apply_info&id=' + id //iframe的url
        }); 
      });

      $('.accept').click(function(event) {
        var id = $(this).attr('data-id');
        layer.confirm('确定通过该用户的申请吗？', {icon: 3, title:false,skin:'layui-layer-rim'}, function(index){
            layer.close(index);
            var index = layer.load();
            $.post('/shop/index.php?act=member_proxy&op=accept_apply&id=' + id,function(msg){
                layer.close(index);
                if(msg == '操作成功！'){
                  layer.msg('操作成功！',{icon:1},function(){
                    location.reload();
                  });
                }
                else{
                  layer.msg(msg,{icon:2},function(){
                    location.reload();
                  });
                }
            });
        });
      });

      $('.reject').click(function(event) {
        var id = $(this).attr('data-id');
        layer.confirm('确定拒绝该用户的申请吗？', {icon: 3, title:false,skin:'layui-layer-rim'}, function(index){
            layer.close(index);
            var index = layer.load();
            $.post('/shop/index.php?act=member_proxy&op=reject_apply&id=' + id,function(msg){
                layer.close(index);
                if(msg == '操作成功！'){
                  layer.msg('操作成功！',{icon:1},function(){
                    location.reload();
                  });
                }
                else{
                  layer.msg(msg,{icon:2},function(){
                    location.reload();
                  });
                }
            });
        });
      });

      $('.delete').click(function(event) {
        var id = $(this).attr('data-id');
        layer.confirm('确定取消该用户的代理资格吗？', {icon: 3, title:false,skin:'layui-layer-rim'}, function(index){
            layer.close(index);
            var index = layer.load();
            $.post('/shop/index.php?act=member_proxy&op=delete_proxy&id=' + id,function(msg){
                layer.close(index);
                if(msg == '操作成功！'){
                  layer.msg('操作成功！',{icon:1},function(){
                    location.reload();
                  });
                }
                else{
                  layer.msg(msg,{icon:2},function(){
                    location.reload();
                  });
                }
            });
        });
      });
    </script>


    <?php if($output['order_pay_list']) { ?>
    <tfoot>
      <tr>
        <td colspan="19"><div class="pagination"> <?php echo $output['show_page']; ?> </div></td>
      </tr>
    </tfoot>
    <?php } ?>
  </table>
</div>
<script charset="utf-8" type="text/javascript" src="<?php echo RESOURCE_SITE_URL;?>/js/jquery-ui/i18n/zh-CN.js" ></script>
<script charset="utf-8" type="text/javascript" src="<?php echo RESOURCE_SITE_URL;?>/js/sns.js" ></script>
<script type="text/javascript">
$(function(){
    $('#query_start_date').datepicker({dateFormat: 'yy-mm-dd'});
    $('#query_end_date').datepicker({dateFormat: 'yy-mm-dd'});
});
</script>
